<?php include template('header','common');?>
<link rel="stylesheet" type="text/css" href="{__ROOT__}template/default/statics/css/tuobanquan-detail.css?v={HD_VERSION}">
<script type="text/javascript" src="{__ROOT__}statics/js/haidao.validate.js?v={HD_VERSION}"></script>

<div class="mask-pinlun" style="display:none;">
	<input name="content" type="text" placeholder="评论">
	<input type="hidden" name="id"  />
	<input type="hidden" name="uid"  />
	<input type="hidden" name="rid"  />
	<!--img src="{__ROOT__}template/default/statics/img/biaoqin.png" alt=""-->
	<span class="active active1">发送</span>
</div>
<div class="container">
	<div class="content">
		<div class="list">
			<div class="item">
				<div class="item-left">
					<img src="{$info['user']['avatar']}" alt="">
				</div>
				<div class="item-right">
					<div class="item-content">
						<span>{$info['user']['truename']}</span>
						<span>{$info['title']}</span>
					</div>
					{if $info['material']}
					<div class="item-img">
						<?php foreach($v['material'] as $kk => $vv){
						$arr=explode('.', $vv);
						if($arr[count($arr)-1] == 'MP4' || $arr[count($arr)-1] == 'MOV'){
						?>
						<video src="{$vv}" style=" height:80px; width:80px; border:1px solid #ccc;" controls preload></video>
						<?php }else{?>
						<img src="{$vv}" alt="" class="contentImg" id="{$v['id']}" style="height:80px;">
						<?php }}?>
					</div>
					{/if}
					<div class="discuss">
						<img class="ping-img" id="btn-img" src="{__ROOT__}template/default/statics/img/pinglun.png" alt="">
						<div class="edit-list" id="btn-ping"{if $member['group_id'] == 3} style="width:225px;"{/if}>
							{if $member['group_id'] == 3}
							<span class="delete" data-id="{$info['id']}"  data-uid="{$info['mid']}">
								<i>删除</i>
							</span>
							{/if}
							<span class="like" data-id="{$info['id']}"  data-uid="{$info['mid']}">
								{if $info['mylike'] > 0}
								<img src="{__ROOT__}template/default/statics/img/zan.png" alt="">
								<i>取消赞</i>
								{else}
								<img src="{__ROOT__}template/default/statics/img/zan.png" alt="">
								<i>赞</i>
								{/if}
							</span>
							<span class="btn-ping" data-id="{$info['id']}"  data-uid="{$info['mid']}">
								<img src="{__ROOT__}template/default/statics/img/pinglun1.png" alt="">
								<i>评论</i>
							</span>
						</div>
					</div>
					
					<div class="discuss-detail">
						<i class="sanjia"></i>
						<div class="discuss-detail-head" id="like-list-{$info['id']}" {if !$info['like']}style="display:none;"{/if}>
							<img src="{__ROOT__}template/default/statics/img/like.png" alt="">
							<?php foreach($info['like'] as $kk => $vv){
							if($i > 0){
								$vv['truename'] = ",&nbsp;".$vv['truename'];
							}
							$i++;
							?>
							<span id="like{$info['id']}{$vv['id']}">{$vv['truename']}</span>
							<?php }?>
						</div>
						<ul class="discuss-list" id="comments-list-{$info['id']}" {if !$info['comments']}style="display:none;"{/if}>
							<?php foreach($info['comments'] as $kk => $vv){?>
							<li class="revert" data-id="{$info['id']}" data-uid="{$info['mid']}" data-rid="{$vv['mid']}">
								{if $vv['rid'] > 0}
								<span>{$vv['truename']}</span>回复<span>{$vv['rtruename']}:</span>
								{else}
								<span>{$vv['truename']}:</span>
								{/if}
								{$vv['content']}
							</li>
							<?php }?>
						</ul>
					</div>

				</div>
			</div>
		</div>
	</div>
</div>
<link type="text/css" rel="stylesheet" href="{__ROOT__}statics/js/upload/uploader.css?v={HD_VERSION}" />
<script type="text/javascript" src="{__ROOT__}statics/js/upload/uploader.js?v={HD_VERSION}"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> 
<script>
	$(".like").click(function(){
		var id = $(this).attr('data-id');
		var uid = $(this).attr('data-uid');
		var _this = $(this);
		var ajaxurl="<?php echo url('school/ring/likes')?>";
		$.post(ajaxurl,{'id':id,'uid':uid},function(ret){
			if(ret.status == 1){
				if(ret.result.type == 0){
					$("#like-list-"+ret.result.id).show();
					if($("#like-list-" + ret.result.id).children('span').length > 0){
						$("#like-list-"+ret.result.id).append('<span id="like'+ret.result.id+ret.result.cid+'">,&nbsp;'+ret.result.truename+'&nbsp;</span>');
					}else{
						$("#like-list-"+ret.result.id).append('<span id="like'+ret.result.id+ret.result.cid+'">'+ret.result.truename+'&nbsp;</span>');
					}
					_this.children("i").text("取消赞");
				}else if(ret.result.type == 1){
					$("#like"+ret.result.id+ret.result.cid).remove();
					if($("#like-list-"+ret.result.id).children('span').length == 0){
						$("#like-list-"+ret.result.id).hide();
					}
					_this.children("i").text("赞");
				}
			}else{
				alerts(ret.message);
			}
		},'json');
	});
	
	$(".delete").click(function(){
		var id = $(this).attr('data-id');
		var _this = $(this);
		var ajaxurl="<?php echo url('school/ring/delete')?>";
		$.post(ajaxurl,{'id':id},function(ret){
			if(ret.status == 1){
				alerts(ret.message,1,ret.referer);
			}else{
				alerts(ret.message);
			}
		},'json');
	});
	
	$(".active1").click(function(){
		var id = $("[name='id']").val();
		var uid = $("[name='uid']").val();
		var rid = $("[name='rid']").val();
		var content = $("[name='content']").val();
		var _this = $(this);
		var ajaxurl="<?php echo url('school/ring/message')?>";
		$.post(ajaxurl,{'id':id,'uid':uid,'rid':rid,'content':content},function(ret){
			if(ret.status == 1){				
				$("#comments-list-"+ret.result.id).show();
				if(ret.result.rid > 0){
					$("#comments-list-"+ret.result.id).append('<li data-id="'+ret.result.id+'" data-uid="'+uid+'" data-rid="'+ret.result.mid+'"><span>'+ret.result.truename+'</span>回复<span>'+ret.result.rtruename+':</span>'+content+'</li>');
				}else{
					$("#comments-list-"+ret.result.id).append('<li data-id="'+ret.result.id+'" data-uid="'+uid+'" data-rid="'+ret.result.mid+'"><span>'+ret.result.truename+':</span>'+content+'</li>');
				}
				$("[name='content']").val('')
			}else{
				$("[name='content']").val('')
				alerts(ret.message);
			}
		},'json');
	});
	var uploader = WebUploader.create({
		auto:true,
		fileVal:'upfile',
		// swf文件路径
		swf: '{__ROOT__}statics/js/upload/uploader.swf',
		// 文件接收服务端。
		server: "<?php echo url('attachment/index/upload')?>",
		// 选择文件的按钮。可选
		formData:{
			file : 'upfile',
			upload_init : '<?php echo $attachment_init ?>'
		},
		// 压缩图片大小
		compress:{
			width: 408,
			height: 408,
			quality: 80,
			allowMagnify: false
		},
		// 内部根据当前运行是创建，可能是input元素，也可能是flash.
		pick: {
			id: '#file-avatar',
			multiple:false
		},
		accept:{
			title: '图片文件',
			extensions: 'gif,jpg,jpeg,bmp,png',
			mimeTypes: 'image/*'
		},
		chunked: false,
		chunkSize:1000000,
		resize: false
	});
	uploader.onFileQueued = function(file){
		alerts("图片上传中...", 3);
	}
	uploader.onUploadError = function(file,reason){
		alerts("图片上传失败");
	}
	uploader.onUploadSuccess = function(file, response) {
		if(response.status == 1) {
			window.location.href="<?php echo url('school/ring/add')?>&img="+response.result.url;
			//$("input[name=head]").attr("value", response.result.url);
			//$(".head").find('img').attr("src", '{__ROOT__}'+response.result.url);
		} else {
			alerts(response.message);
		}
	}
	$(".ping-img").click(function () {
		$(".edit-list").hide();
		$(this).next().fadeToggle();
		$(this).next().css("display", "flex");
		$('body').bind('click', function (event) {
			// IE支持 event.srcElement ， FF支持 event.target			
			var evt = event.srcElement ? event.srcElement : event.target;
			console.log(evt.className);
			if (evt.id == 'btn-ping' || evt.id == "btn-img") return; // 如果是元素本身，则返回
			else {
				$('#btn-ping').hide(); // 如不是则隐藏元素
			}
		});
	});
	
	$(window).on('touchmove',function(){
		$(".mask-pinlun").hide();
		$(".edit-list").hide();
		$(".mask-pinlun input").blur();
	});

    /*$(".img-btn").click(function () {
        $(".mask").show();
        $(".mask-img").show();
    })*/
    $(".mask").click(function () {
        $(this).hide();
        $(".mask-img").hide();
    })
    $(".mask-item3").click(function () {
        $(".mask-img").hide();
        $(".mask").hide();
    });
    $(".btn-ping").click(function () {
		var id = $(this).attr('data-id');
		var uid = $(this).attr('data-uid');
		var rid = $(this).attr('data-rid');
		$("[name='id']").val(id);
		$("[name='uid']").val(uid);
		$("[name='rid']").val(rid);
        $(".mask-pinlun").css("display", "flex");
        $(this).parent().hide();
        $(".mask-pinlun input").focus();
		$(".mask-pinlun input").attr("placeholder","评论")
        $(".edit-list").hide;
        $('body').bind('click', function (event) {
            // IE支持 event.srcElement ， FF支持 event.target  
            var evt = event.srcElement ? event.srcElement : event.target;
            if (evt.className == 'mask-pinlun'||evt.className==''||evt.className == 'btn-ping') return; // 如果是元素本身，则返回
            else {
                $('.mask-pinlun').hide(); // 如不是则隐藏元素
            }
        })
    });
	
	$(".revert").click(function () {
		var id = $(this).attr('data-id');
		var uid = $(this).attr('data-uid');
		var rid = $(this).attr('data-rid');
		$("[name='id']").val(id);
		$("[name='uid']").val(uid);
		$("[name='rid']").val(rid);
        $(".mask-pinlun").css("display", "flex");
        $(".mask-pinlun input").focus();
		$(".mask-pinlun input").attr("placeholder","回复"+$(this).children('span:first-child').text()+"")
        $(".edit-list").hide;
        $('body').bind('click', function (event) {
            // IE支持 event.srcElement ， FF支持 event.target  
            var evt = event.srcElement ? event.srcElement : event.target;
            if (evt.className == 'mask-pinlun'||evt.className==''||evt.className == 'btn-ping'||evt.className == 'revert') return; // 如果是元素本身，则返回
            else {
                $('.mask-pinlun').hide(); // 如不是则隐藏元素
            }
        })
    });
	$(function(){
		var imgsurl=[];  
		var nowurl='';  
		var imgObj=$(".item-img img");  
		for(var i=0;i<imgObj.length;i++){  
			imgsurl[i]=imgObj[i].src;  
			imgObj[i].onclick=function(){  
				nowurl=this.src;  
				wx.previewImage({  
					current: nowurl,  
					urls: imgsurl  
				});               
			}  
		}  
	});
</script>
<?php include template('footer','common');?>